﻿namespace LinesOfAction.Converters
{
    using System;
    using System.Globalization;
    using System.Windows.Data;
    using System.Windows.Markup;

    public class MultiplierConverter : MarkupExtension, IValueConverter
    {
        public MultiplierConverter()
        {
            
        }

        public double Fator { get; set; }

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return (double) value*Fator;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                return (double) value/Fator;
            }
            catch (DivideByZeroException)
            {
                return value;
            }
        }

        #endregion

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return this;
        }
    }
}